Skip to content

M4c-1: bullseye::Style contract, owned widgets, paint translate, selectable text - #38

Merged
samitbasu merged 19 commits into
mainfrom
m4c-spike
Nov 9, 2026
Merged

samitbasu merged 19 commits into
mainfrom
m4c-spike

Conversation

@samitbasu

@samitbasu samitbasu commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Part of #19. Closes #39. This started as the spike; the user then decided on the full owned split.

Contract: bullseye::Style (src/contract.rs)

  • Sections: one per widget (button, checkbox, radio, switch, segmented, slider, select, stepper, focus, selection, text, label).
  • Defaults: #[non_exhaustive] with a neutral Default derived from egui, so core works with no preset.
  • Per-state colours: rest, hover, pressed, focused and disabled.
  • Open keys: button variants and sizes are style-defined. An unknown key falls back to the default; it is a debug_assert! in debug and never panics.
  • Access: Style::of(ctx) is cached per theme. install and install_for set it. The shadcn preset fills it; the preset moves to its own crate in M4c-2.

Owned widgets (src/owned/)

  • The set: button (variants, toggle, opens_popup), checkbox, radio group, switch, segmented, slider, select trigger, and stepper (Second reference app (an operator console): requirements and gaps #22).
  • All of them are built from nodes, measured by taffy, styled exactly from the contract in light and dark, with explicit disabled colours and accessibility roles, labels and states. The kittest accessibility check passes.
  • Keyboard:
    • Tab, Space and Enter everywhere;
    • radio groups are one Tab stop, with arrow keys inside;
    • slider: arrows, PageUp/PageDown, Home and End;
    • select: Space, Enter or ArrowDown opens; arrows, Enter and Esc;
    • stepper: ArrowUp and ArrowDown.
  • Labels: NodeUi::label_for links a label to its control for accessibility and forwards its clicks.
  • Removed: the wrapped Button, Checkbox, RadioButton, Slider, ComboBox and DragValue, along with their size-estimate engine, egui-visuals styling and drift guards. Only TextEdit stays wrapped.

Paint translate and press feedback

Paint::translate / translate_y move a node's and its subtree's painting (and clip), not its layout or hit rects. It eases with transition. Owned buttons sink 1 pt while pressed, except ones marked opens_popup.

Selectable text (#39)

  • How: text nodes paint through egui's label selection with the measured galley, so selection works across nodes and Ctrl+C copies. Layout is pixel-identical: no golden changed in that commit.
  • Default rule: text is selectable unless it, or an ancestor, senses the pointer. select_text() and select_none() override this. Owned controls are select_none.

Size (cargo xtask loc, code lines)

Lines
Before the spike 4,915
Peak, with both the owned and wrapped paths 7,153
Now 6,436

That is about 1,000 lines over the spike's projection; the overrun is mostly behaviour (select and stepper keyboard models, radio roving focus). The ~740-line wrapped-widget drift-guard suite is gone, except TextEdit's.

UI changes to try

cargo xtask example controls_gallery (Section: owned), form, signup_form, chat_shell, kaolin, flex_example, button. 25 goldens changed, all from the owned controls (shadcn sizes, owned select chevron, explicit disabled colours). In flex_example, the grow buttons no longer stretch to their line's height.

Deferred

  • M4c-2: the bullseye-shadcn crate, Accent → ThemeColor, vega and lyra, the TextEdit mapping, and the popup-style check.
  • M6: an overlay for the select popup.
  • Vertical slider.
  • Hold-to-repeat on the stepper.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up

samitbasu and others added 2 commits November 8, 2026 15:25
Counts lines of code per file and directory, leaving out blanks, comments
(line, doc, block) and #[cfg(test)] items, so each milestone can quote the
size of the library. Takes an optional root, default src.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Button (five variants, toggle, disabled) and Checkbox are identified nodes
with a sense, hover/active/focus variants and text or paint children, styled
from a draft bullseye::Style (src/owned/style.rs, vega values) and measured
by taffy, so there is no size estimate. Disabled is inert plus explicit
colours; the focus ring is a real focus variant (ring-[3px] ring/50,
border-ring). The gallery gets an owned section beside the wrapped widgets,
with a Section switch in its panel; the four existing gallery goldens change
only by that added control. Press feedback (paint translate) is not built.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
samitbasu and others added 8 commits November 8, 2026 16:18
M4c-1, part 1. bullseye::Style is the contract core widgets draw from;
the shadcn preset in style.rs now fills it (Shadcn::style) and installs it
for its theme on apply. Core has a neutral default derived from egui's
visuals, cached per egui style, so it works with no preset.

Style: nested per widget (button, checkbox, radio, switch, segmented,
focus, selection, link, label, text), #[non_exhaustive] with Default.
Per-state colours (rest, hover, pressed, focused, disabled; selected is
the on look), open Variant and Size keys held in Keyed, whose unknown key
asserts in debug and falls back to the default entry in release.
Style::install / install_for(theme) put it in the egui context.

Paint::translate / translate_y: paint-only, moves the node's and its
subtree's shapes (and their clips) like a CSS transform; layout and hit
rects stay, and it eases with transition. Owned buttons shift down the
style's press_shift on active, except those marked opens_popup().

Owned widgets: button (variants, sizes, toggle, disabled, focus ring,
press feedback), checkbox, RadioGroup (arrow keys move choice and focus),
Switch (replaces prim::switch; track and thumb per state from the style)
and Segmented (replaces prim::segmented and SegmentedClasses, one Tab stop
per cell; show_with keeps hand-written cell classes for custom looks).

NodeUi::label_for names a control by a label node (accesskit
labelled_by) and returns whether the label was clicked, so choice
controls forward label clicks. Builder::paint closures now get the node's
resolved text colour, which the switch thumb and the check glyph use.

Behaviour changes: prim::switch, prim::segmented and
style::SegmentedClasses are removed; owned::variant moved to
style::variant (typed Variant keys); a switch's label is drawn from
Style.text and its row is no longer 36pt tall (shadcn's compact switch);
controls_gallery's cells section no longer lists switch and segmented.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
controls_gallery_owned_{light,dark} now show every owned widget beside
the wrapped one where there is one (radio group, switch and segmented
have no wrapped form). The cells goldens lose the switch and segmented
cells; form.png draws its switches from the contract (14pt labels, the
compact 18.4pt track row).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
M4c-1, part 2. Three more owned widgets drawn from new Style sections, each
measured by taffy, with widget_info and kittest's accessibility check on.

Style: slider (track, range, thumb Looks, track height, thumb size), select
(trigger Look and Metrics, chevron size and opacity, popup box, item Look)
and stepper (field Look and box metrics, button Look and size, glyph, gap).
The shadcn preset fills them with vega (h-1.5 muted track, primary range,
size-4 thumb with border and shadow-sm; h-9 input-like trigger; popover
list with accent-highlighted items; the outline button look for the
stepper's buttons). Tokens gains shadow_md. Colors, States and Look gain
towards(), a mix by Progress.

Slider: pressing the track jumps the thumb, dragging the track or thumb
follows the pointer, values snap to a Step. Thumb focused: arrows step,
PageUp/PageDown ten steps, Home/End the ends. Role Slider with value, min
and max. Absolute thumb in a rail, so it needs no measured width.

Select: trigger is a node that opens_popup (no press shift). The list is
egui's Popup, drawn in the style's popup and item colours until M6 gives
bullseye overlays. Space/Enter/ArrowDown open; arrows, Home/End move the
highlight; Enter/Space choose; Escape closes and keeps focus. Role ComboBox
with value and expanded state.

Stepper (#22): a text field in a box plus two stacked chevron buttons,
clamped to a range. ArrowUp/ArrowDown in the field step, typing applies
numbers as they parse and snaps to the step on blur, the buttons disable at
the limits and are not Tab stops. Own style section because its buttons are
smaller than any button size and hold a glyph. Role SpinButton.

Step is a positive-only newtype shared by slider and stepper; paint_check
moved from checkbox to owned/mod.rs beside the new chevron.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
)

Fixes from part 1's review.

Radio group: one Tab stop, on the chosen option, as HTML and WAI-ARIA radio
groups do. The other circles are focusable_none. Arrows still move choice
and focus; the focus moves once the choice has made the target the stop,
since egui drops focus given to a node that is not focusable yet. Segmented
keeps a Tab stop per segment, as shadcn's toggle group does.

Switch: the track (and thumb) colours ease between the off and on looks over
the slide time, instead of switching, and the thumb is drawn in the rest
colour in every state, so hover and pressed no longer tint it.

Behaviour changes: Tab visits a radio group once; Shift+Tab re-enters on the
chosen option.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
…#19, #22)

controls_gallery's owned section gains slider and select rows beside their
wrapped forms (named, so the accessibility check passes) and a stepper row;
signup_form's Age is a stepper instead of a DragValue (its test types the
age). The owned-section snapshots are 1160 points tall so every row shows.

Goldens changed: controls_gallery_owned_light/dark (new rows),
signup_form_empty/rejected (stepper in place of the drag value).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Text nodes paint through LabelSelectionState with the same measured galley
at the same anchor, so drag-select across nodes and Ctrl+C come from egui and
pixels and layout match plain painting. Default follows CSS: text is
selectable unless the node or an ancestor senses the pointer; select_text()
and select_none() override it (inherited like the other text classes).
Owned controls are select_none. The selection registers over the whole
content box, so a drag may end in the blank beside the text; it is not a Tab
stop. Colours come from Style::selection.

Per-text-node cost for M8: a selectable text node now opens a child Ui, makes
one widget registration and hit test, takes the selection plugin lock and
looks up an id counter, where plain painting was one painter call.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
…#19)

Deleted the wrapped Button, Checkbox, RadioButton, Slider, ComboBox and
DragValue, prim::select, the atom-layout estimate engine in sizing.rs, the
egui-visuals styling functions (style_button, style_toggle, style_slider,
style_checkbox, style_radio), ButtonVariant and Tokens::slider_height.
widget.rs is now TextEdit only, with Stock and Builder::widget kept for it;
prim::text_field stays as the public text input (a measure/show pair over
TextEdit) because owned controls have no text input.

Owned API: Button::classes (the width and growth the examples set on a
button's leaf) and Checkbox/Switch take any Copy closure, not a fn pointer.

Examples and tests are migrated. The gallery's cells section checks only the
text edits; its owned section loses the wrapped column. Drift guards in
tests/it/sizing.rs keep the TextEdit cases (button, button variants,
selectable, checkbox, radio, slider, drag value, combo box removed);
widget_looks.rs, the wrapped-look tests in style.rs and the wrapped cases in
widgets.rs and prims.rs are gone, their owned counterparts live in owned*.rs.

Intentional behaviour changes: every example's buttons, checkboxes, sliders
and selects are the owned ones (shadcn sizes and colours from the contract,
disabled by colour rather than half opacity); owned buttons have a fixed
height so grow buttons in flex_example no longer fill their line's height;
node paths gained the owned parts (/Terms/Box, /Slider/Track).
Goldens regenerated and reviewed: chat_shell (select), controls_gallery
(cells and owned), flex_demos, flex_example, form, kaolin, port_button,
port_custom_background, port_flex_grid, port_flex_wrap, port_grow,
signup_form (owned controls in place of the wrapped ones).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
…nk (#19)

Enablement::apply and Enablement::colors replace four hand-written matches;
centered, Look::indicator (checkbox box and radio circle) and described (role,
name and on/off state of the node's response, six call sites) replace the
repeated class chains and widget_info blocks. Style::link was read by nothing
and is removed with its preset values; every other contract field is read by
a widget. The Accent type is still used by the examples and tests, so it
stays until the M4c-2 rename.

No behaviour change: no test outcome and no golden changed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
@samitbasu samitbasu changed the title M4c spike: owned vs wrapped Button and Checkbox (for decision) M4c-1: bullseye::Style contract, owned widgets, paint translate, selectable text Nov 9, 2026
samitbasu and others added 6 commits November 8, 2026 21:53
)

The range is rounded_full: egui clips to rectangles, so the track's
overflow-hidden no longer rounds it, and a fully rounded range is exact at
0 and max where the range meets the track's ends.

Disabled colours were per-shape 50% alpha, so the track showed through the
disabled thumb. They are now each colour composited over the surface it sits
on and blended halfway to it (CSS group opacity for opaque parts); a
transparent part stays transparent. States::new/still take that surface.
The shadcn preset uses background (popover for the select popup and items,
muted for segmented cells); from_egui uses panel_fill.

Behaviour change: disabled looks are opaque; Colors::faded is replaced by
Colors::faded_over, and States::new/still gain a surface argument.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
…fferences (#19, #40)

The owned controls did not fit the example's window. The Section control now
selects cells, buttons, choices or values, and the example opens at an explicit
1280x800 (WINDOW, via common::run_app_sized), which each section's golden uses
in light and dark and asserts everything fits. The stepper gains a disabled
row. The crate docs gain a Differences from CSS section: no backdrop blur, no
rounded clipping, no group opacity.

Replaces controls_gallery_owned_{light,dark} with controls_gallery_{buttons,
choices,values}_{light,dark}. The slider goldens elsewhere change because the
range is now rounded.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
…buttons

The focus ring was drawn around the text field's own box, a sibling of the
up/down buttons, so its 3pt halo covered them. The stepper is now one
container with the input border, radius, background and shadow, holding the
bare text field on the left and a column of two ghost-styled buttons on the
right, split from the field and from each other by 1pt dividers. The ring and
ring-coloured border go on the container through focus-within, so they
enclose the buttons instead of crossing them. The buttons round their own
outer corners (new Tw rounded_tr_px / rounded_br_px) since egui cannot clip to
rounded shapes (#40). A disabled stepper paints the whole group in the opaque
disabled colours.

Contract changes (breaking): StepperStyle drops field_radius, button_size,
button_radius and gap; field is renamed group, radius replaces field_radius,
and button_width and divider are added. The shadcn preset's stepper button is
now the ghost look and its divider the input colour.

Goldens: controls_gallery_values_*, signup_form_*, and new
controls_gallery_stepper_focused_{light,dark} showing the ring.

Refs #19, #22.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
… text section

The Section control wrapped onto two rows in the 240pt aside. Its labels are
now text, button, choice, value, which fit on one row (the control no longer
goes through common::choice, whose wrapping rule is for more than three
segments). Cell width, Text size, button_padding, interact_size, Label and the
blue/orange/red legend only affect the text (cells) section, so they show only
while it is selected.

Intentional changes: the section labels, and the aside of the button, choice
and value sections now holds only the Section control.

Tests assert the four segments share one row inside the aside, and that the
cell controls and legend appear only for the cells section. Goldens
regenerated: every controls_gallery_*.

Refs #19.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
The gallery's Section control shifted its labels when the selection
changed: the shadcn preset gave the selected cell a 1pt border in dark
and the others none. shadcn's TabsTrigger keeps `border-transparent` on
every trigger and only changes the colour.

Make that unrepresentable. `Look` is split into `Paint` (colours per
state, shadow, focus ring: nothing that takes room) and `Look { paint,
border_width }`. Widgets that swap looks by state now hold two `Paint`s
and one border width: `ButtonStyle::{toggle_off, toggle_on,
toggle_border_width}`, `CheckboxStyle`, `RadioStyle` and `SwitchStyle`
({off, on, border_width}), `SegmentedStyle::{selected, unselected,
cell_border_width}`. Widgets with one look (button variants, slider
thumb, select, stepper) keep `Look`. Padding, height and radius were
already per-widget.

Preset: every segmented cell has a 1pt border; unselected is transparent,
selected is `input` in dark and transparent in light. The neutral default
is unchanged in size (toggle and segmented 0pt, choices 1pt).

Behaviour changes:
- Segmented cells in the shadcn preset are 2pt wider (1pt border each
  side) in light and for the unselected cells in dark; goldens with a
  segmented control move accordingly.
- The gallery's panel is 248pt wide (was 240) so the Section control,
  now wider, still fits it.

New test state_stable drives real clicks on a toggle button, checkbox,
radio, switch and segmented control in both themes and asserts every
node rectangle is unchanged; it fails on the previous code (segmented,
dark).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Transitions blended egui's linear animation straight into colours, opacity
and the paint translate. Tailwind's `transition` eases along
cubic-bezier(0.4, 0, 0.2, 1) by default, which shadcn relies on.

Add `Easing` (Linear, In, Out, InOut, Default) with `Easing::ease`, which
solves x(t) = progress on the cubic Bezier (Newton from the linear guess,
bisection fallback) and returns y(t). egui stays the clock; the curve is
applied to the animated progress in `presence`, before blending, and state
stays keyed by node id. `Tw` gains `ease_linear/in/out/in_out`; `transition`
without one uses the default curve. The switch's thumb slide and track
colour use the default curve too. No contract field: nothing needs a curve
different from its transition's.

Behaviour change: mid-transition values of every transition (hover, active,
focus, group_hover, press translate, switch) now follow the curve instead of
linear; start and end values are unchanged. No existing test or golden
changed. New tests sample a 500ms transition against the linear clock.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
@samitbasu

Copy link
Copy Markdown
Owner Author

The user approved the controls gallery on try-out. CI is green. Marked ready for the user to merge. #41 (API ergonomics) is still under consideration and is not part of this PR.

samitbasu and others added 3 commits November 9, 2026 08:56
With Debug::Outlines on, a monospace readout in the top-right corner of the
debug layer shows egui's unstable_dt and the fps averaged over the last 30
passes, stable_dt and predicted_dt (which decide how far animations advance
per frame), bullseye's own build, layout and draw time summed over every tree
of the pass, and whether a repaint is requested or egui is idle. One readout
per pass: later trees replace the earlier one's shape. Off does no timing and
no temp-data writes.

Adds web-time as a direct dependency at egui's version (wasm-safe Instant).
The clock check now accepts web_time::Instant and still rejects
std::time::Instant. The debug_overlay_todo golden masks the readout box, as
its numbers are measured.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Egui's animate_*_with_time advances by stable_dt per frame and caps the
first frame after idle at predicted_dt, so at 5 fps a 150ms press took
~600ms. All transitions now share one clock path, transition::animate,
driven by input.time (refs #19).

Per transition (keyed by node id + state, in egui temp data) it stores
{ from, target, start, duration }. When the target flips, the current
eased value becomes the new `from`, start becomes now, and the duration
is the configured one scaled by the distance left (CSS reversing
shortening). Progress is elapsed/duration clamped, eased, then lerped
from `from` to `target`. Repaints are requested only while in flight;
zero duration applies immediately; a first sighting starts settled.

Call sites: variant presence (hover, active, focus, focus_within,
group_hover; the paint translate follows presence) and the switch's
track colour and thumb slide.

Behaviour changes: transitions last their duration at any frame rate;
mid-flight reversals are shortened. Public API unchanged.

Tests changed: owned_choice thumb_slides_between_the_ends and
switch_track_eases_to_its_new_colour flipped the switch by click and
sampled one 50ms step later, relying on the old slow-motion (150ms
slide now completes within the click's trailing steps); they now flip
app state and sample two steps in. Added: 5 fps and 16 ms frame clocks,
reversal, repaint requests, keyed reorder mid-flight.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
The click's own steps now cover only part of the 150ms slide, so the
mid-slide sample is a precondition-checked in-between value reached
through the real input path rather than a direct app-state flip (refs #19).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
@samitbasu
samitbasu merged commit dbcd6bf into main Nov 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Selectable text: render text nodes through egui Labels from the measured galley

1 participant